home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-2.iso / Files II / Prog / M / MacWT 0.04.sit / Mac WT source / wt / linuxvga.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  2.9 KB  |  122 lines

  1. /*
  2. **  wt -- a 3d game engine
  3. **
  4. **  Copyright (C) 1994 by Chris Laurel
  5. **  email:  claurel@mr.net
  6. **  snail mail:  Chris Laurel, 5700 W Lake St #208,  St. Louis Park, MN  55416
  7. **
  8. **  This program is free software; you can redistribute it and/or modify
  9. **  it under the terms of the GNU General Public License as published by
  10. **  the Free Software Foundation; either version 2 of the License, or
  11. **  (at your option) any later version.
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. **  GNU General Public License for more details.
  17. **
  18. **  You should have received a copy of the GNU General Public License
  19. **  along with this program; if not, write to the Free Software
  20. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22.  
  23. /*
  24.  * Modified:
  25.  * Handle virtual screen graphics with vgagl. This allows for
  26.  * transparent page flipping in 256 color modes, including SVGA resolutions.
  27.  * Also supports planar (mode X-like) 256 color modes, and even 16-color
  28.  * modes.
  29.  *
  30.  * Triple-buffering is automatically used by vgagl if enough video memory
  31.  * is available.
  32.  */
  33.  
  34.  
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <stdio.h>
  38. #include <vga.h>
  39. #include <vgagl.h>
  40. #include <vgakeyboard.h>
  41. #include "wt.h"
  42. #include "error.h"
  43. #include "wtmem.h"
  44. #include "framebuf.h"
  45. #include "graphics.h"
  46.  
  47.  
  48. static void load_palette(void);
  49.  
  50. static int graphics_initialized = 0;
  51. static Pixel *fb_mem;
  52.  
  53. GraphicsContext physicalscreen;
  54.  
  55.  
  56. void init_graphics(void)
  57. {
  58.     int vgamode;
  59.  
  60.  
  61.     vga_init();        /* This gives up root priviledges. */
  62.     vgamode = G320x200x256;
  63.     vga_setmode(vgamode);
  64.     gl_setcontextvga(vgamode);
  65.     gl_getcontext(&physicalscreen);
  66.     load_palette();
  67.     /* Create the virtual screen framebuffer. */
  68.     gl_setcontextvgavirtual(vgamode);
  69.     fb_mem = VBUF;    /* VBUF points to the virtual screen framebuffer. */
  70.  
  71.     /* The following function returns 3 if triple-buffering is used,
  72.      * 2 for double-buffering, 0 otherwise. */
  73.     gl_enablepageflipping(&physicalscreen);
  74.  
  75.     graphics_initialized = 1;
  76. }
  77.  
  78.  
  79. void load_palette(void)
  80. {
  81.      FILE *fp;
  82.      int r, g, b;
  83.      int i;
  84.  
  85.      fp = fopen(DEFAULT_PALETTE_FILE, "rb");
  86.      if (fp == NULL)
  87.       fatal_error("unable to open palette file");
  88.      for (i = 0; i < PALETTE_ENTRIES; i++) {
  89.       r = getc(fp);
  90.       g = getc(fp);
  91.       b = getc(fp);
  92.       if (b == EOF)
  93.            fatal_error("error reading palette file");
  94.       vga_setpalette(i, r, g, b);
  95.      }
  96.  
  97.      fclose(fp);
  98. }
  99.  
  100.  
  101. void end_graphics(void)
  102. {
  103.      if (graphics_initialized) {
  104.       keyboard_close();    /* This is required! */
  105.       vga_setmode(TEXT);
  106.       graphics_initialized = 0;
  107.      }
  108. }
  109.  
  110.  
  111. void update_screen(Framebuffer *fb)
  112. {
  113.     /* Page flipping is done transparently. */
  114.     gl_copyscreen(&physicalscreen);
  115. }
  116.  
  117.  
  118. Pixel *get_framebuffer_memory(int width, int height)
  119. {
  120.      return fb_mem;
  121. }
  122.